package cs2114.antiFingerMines;

import android.view.KeyEvent;
import android.app.Activity;
import android.app.Instrumentation.ActivityMonitor;
import android.widget.Button;

// -------------------------------------------------------------------------
/**
 *  This class tests the Menu activity
 *
 * @author Blake Whaley
 * @author Graham McLaughlin (gjm1324)
 * @author William Vuong (wnvuong)
 * @version 2012.29.4
 */
public class AntiFingerMinesMenuTest
    extends student.AndroidTestCase<AntiFingerMinesMenu>
{

    /**
     * Create a new AntiFingerMinesMenuTest object.
     */
    public AntiFingerMinesMenuTest()
    {
        super(AntiFingerMinesMenu.class);
    }

    private ActivityMonitor easyMonitor;
    private ActivityMonitor mediumMonitor;
    private ActivityMonitor hardMonitor;

    /**
     * Sets the variables needed for testing
     */
    public void setUp() throws Exception
    {
        super.setUp();
        easyMonitor = new ActivityMonitor(AntiFingerMinesEasy.class.
            getName(), null, false);
        getInstrumentation().addMonitor(easyMonitor);

        mediumMonitor = new ActivityMonitor(AntiFingerMinesMedium.class.
            getName(), null, false);
        getInstrumentation().addMonitor(mediumMonitor);

        hardMonitor = new ActivityMonitor(AntiFingerMinesHard.class.
            getName(), null, false);
        getInstrumentation().addMonitor(hardMonitor);
    }



    /**
     * Tests the easy button
     */
    public void testEasy()
    {
        Button easy = getView(Button.class, R.id.EasyGame);
        click(easy);
        Activity easyGame = easyMonitor.waitForActivityWithTimeout(1000);
        assertNotNull("Activity was not started", easyGame);
        sendKeys(KeyEvent.KEYCODE_BACK);

    }

    /**
     * Tests the medium button
     */
    public void testMedium()
    {
        Button medium = getView(Button.class, R.id.MediumGame);
        click(medium);
        Activity mediumGame = mediumMonitor.waitForActivityWithTimeout(1000);
        assertNotNull("Activity was not started", mediumGame);
        sendKeys(KeyEvent.KEYCODE_BACK);
    }

    /**
     * Tests the hard button
     */
    public void testHard()
    {
        Button hard = getView(Button.class, R.id.HardGame);
        click(hard);
        Activity hardGame = hardMonitor.waitForActivityWithTimeout(1000);
        assertNotNull("Activity was not started", hardGame);
        sendKeys(KeyEvent.KEYCODE_BACK);
    }

    /**
     * Tests the easy button
     */
    public void testQuit()
    {
        Button quit = getView(Button.class, R.id.Quit);
        click(quit);
        Activity easyGame = easyMonitor.waitForActivityWithTimeout(1000);
        assertNull("Activity was started", easyGame);

        Activity mediumGame = mediumMonitor.waitForActivityWithTimeout(1000);
        assertNull("Activity was started", mediumGame);

        Activity hardGame = hardMonitor.waitForActivityWithTimeout(1000);
        assertNull("Activity was started", hardGame);
    }


}
